import React from 'react';
import ReactDom from 'react-dom';
import { Provider } from 'react-redux';
import { ConfigProvider } from '@teamix/ui';
import 'components/common/index.scss';
import 'components/common/project.scss';
import initPage from 'utils/initPage';
import { initFeatures, getFeature } from 'utils/features';
import createStore from './store/index';
import reducers from './reducers/index';
import Root from './containers/root';
import './index.scss';
import '@alife/aisc-widgets/build/index.css';
import '@alife/yunxiao-member/dist/YunxiaoMember.css?fusionPrefix=.yx-';
import '@alife/yunxiao-list/dist/YunxiaoList.css?fusionPrefix=.yx-';
import '@alife/yunxiao-table/dist/YunxaioTable.css?fusionPrefix=.yx-';
import moment from 'moment';
import { ENV } from '@alife/yunxiao-common';

// 引入 AEM SDK及插件
import AES from '@ali/aes-tracker';
import '@ali/aes-tracker-plugin-jserror';
import '@ali/aes-tracker-plugin-api';
import '@ali/aes-tracker-plugin-perf';
import '@ali/aes-tracker-plugin-longtask';
import { clearAutoPV } from '@ali/aes-tracker-plugin-pv';

// import '@ali/aes-tracker-plugin-autolog'; // 自动事件埋点 https://yuque.antfin-inc.com/aes/help/gbuk7t

const { user } = window.FORCE;

// 初始化功能开关，当前从本地 features/ 目录获取
initFeatures(ENV);

initPage();

// 初始化aem（延迟防阻塞）
if (getFeature('track.needAEM')) {
  setTimeout(() => {
    AES.setConfig({
      pid: 'codeup',
      user_type: '101',
      uid: user && user.id,
      username: user && user.nickname,
    });
    clearAutoPV();
  }, 1500);
}

moment.locale('zh-cn');
export const store = createStore(reducers());

ReactDom.render(
  <Provider store={store}>
    <ConfigProvider prefix="yx-">
      <Root />
    </ConfigProvider>
  </Provider>,
  document.getElementById('container'),
);
